﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace PuzzleGame
{
    public partial class MainPage : UserControl
    {

        private Image[] images;

        public void Shuffle(List<KeyValuePair<int,int>> list)
        {
            Random rng = new Random();
            int n = list.Count;
            while (n > 1)
            {
                n--;
                int k = rng.Next(n + 1);
                KeyValuePair<int, int> value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }


        public MainPage()
        {
            InitializeComponent();
        }
        
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            images = new Image[10];
            List<KeyValuePair<int, int>> positions = new List<KeyValuePair<int, int>>();

            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                {
                    positions.Add(new KeyValuePair<int, int>(i, j));
                    images[3*i+j] = new Image();
                    images[3 * i + j].Source = (new ImageSourceConverter().ConvertFromString("image.jpg")) as ImageSource;
                    images[3 * i + j].Width = 480;
                    images[3 * i + j].Height = 480;
                    TranslateTransform ts = new TranslateTransform();
                    ts.X = -j * 160;
                    ts.Y = -i * 160;
                  //  images[3 * i + j].RenderTransform = ts;
                    RectangleGeometry rg = new RectangleGeometry();
                    rg.Rect = new Rect(j * 160, i * 160, 160, 160);
                   // rg.RadiusX = 20;
                  //  rg.RadiusY = 20;
                    images[3 * i + j].Clip = rg;

                    Grid.SetColumn(images[3 * i + j], j);
                    Grid.SetRow(images[3 * i + j], i);
                    LayoutRoot.Children.Add(images[3 * i + j]);
                }
            Shuffle(positions);


            for (int i = 0; i < positions.Count; i++)
            {
               
            }
        }
    }
}
